<template>
  <div class="login">
    <div class="container">
      <a href="/#/index"><img src="/imgs/login-logo.png" alt=""></a>
    </div>
    <div class="wrapper">
      <div class="container">
        <div class="login-form">
          <h3>
            <span class="checked">注册</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入帐号" v-model="username" @blur="getName">
          </div>
          <span>{{mesName}}</span>
          <div class="input">
            <input type="password" placeholder="请输入密码" v-model="password" @blur="getPwd">
          </div>
          <span>{{mespwd}}</span>
          <div class="input">
            <input type="password" placeholder="请再次输入密码" v-model="password2" @blur="getPwd2">
          </div>
          <span>{{mespwd2}}</span>
           <div class="input">
            <input type="email" placeholder="请输入邮箱" v-model="email" @blur="getEmail">
          </div>
          <span>{{mesEmail}}</span>
          <div class="btn-box">
            <a href="javascript:;" class="btn" @click='toLogin'>注册</a>
          </div>
          <!-- <div class="tips">
          </div> -->
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="footer-link">
        <a href="https://www.imooc.com/u/1343480" target="_blank">袁彤欣主页</a><span>|</span>
        <a href="https://coding.imooc.com/class/113.html" target="_blank">袁彤欣的CSDN</a><span>|</span>
        <a href="https://coding.imooc.com/class/236.html" target="_blank">袁彤欣的gitee</a><span>|</span>
        <a href="https://coding.imooc.com/class/343.html" target="_blank">袁彤欣的项目</a>
      </div>
    <div class="copyright">Copyright ©2022 <span class="domain">mi.futurefe.com</span> All Rights Reserved.</div>
  </div>
  </div>
</template>
<script>
// import { mapActions } from 'vuex';
import { Message } from 'element-ui'

export default {
  name: 'login',
  data(){
    return {
      username:'',
      password:'',
      password2:'',
      userId:'',
      mesName:'',
      mespwd:'',
      mespwd2:'',
      mesEmail:''
    }
  },
  methods:{
    
      // 校验用户名输入是否为空
        getName() {
            if (!this.username) {
                this.mesName = '用户名不能为空'
            } else {
                this.mesName = ''
            }
        },
        
        // 校验密码输入是否符合要求
        getPwd() {
            var pat = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,14}$/;            
            if (!this.pwd) {
                this.mesPwd = '密码不能为空'
            } else if (!pat.test(this.pwd)) {
                this.mesPwd = '密码至少包含小写字母、大写字母和数字且长度不能低于六位'
            } else {
                this.mesPwd = ''
            }
        },
 
        // 校验确认密码是否和密码一致        
        getPwd2() {
            if (!this.pwd2) {
                this.mesPwd2 = '请再次输入密码'
            } else if (this.pwd2 != this.pwd) {
                this.mesPwd2 = '前后密码不一致'
            } else {
                this.mesPwd2 = ''
            }
        },
        
        //点击注册按钮
        toLogin() {
            if (!this.mesName && !this.mesPwd && !this.mesPwd2) {
                alert("注册成功")      
                this.$router.push('login')                                          
            }else {
                // alert("请按要求填写全部信息")
                Message.create('请按要求填写全部信息')
            }
        }

  }
   
}
</script>
<style lang="scss">
.login{
  &>.container{
    height:113px;
    img{
      width:auto;
      height:100%;
    }
  }
  .wrapper{
    background:url('/imgs/login-bg.jpg') no-repeat center;
    .container{
      height:576px;
      .login-form{
        box-sizing: border-box;
        padding-left: 31px;
        padding-right: 31px;
        width:410px;
        height:510px;
        background-color:#ffffff;
        position:absolute;
        bottom:29px;
        right:0;
        h3{
          line-height:23px;
          font-size:24px;
          text-align:center;
          margin:40px auto 49px;
          .checked{
            color:#FF6600;
          }
          .sep-line{
            margin:0 32px;
          }
        }
        .input{
          display:inline-block;
          width:348px;
          height:50px;
          border:1px solid #E5E5E5;
          margin-bottom:20px;
          input{
            width: 100%;
            height: 100%;
            border: none;
            padding: 18px;
          }
        }
        .btn{
          width:100%;
          line-height:50px;
          margin-top:10px;
          font-size:16px;
        }
        .tips{
          margin-top:14px;
          display:flex;
          justify-content:space-between;
          font-size:14px;
          cursor:pointer;
          .sms{
            color:#FF6600;
          }
          .reg{
            color:#999999;
            span{
              margin:0 7px;
            }
          }
        }
      }
    }
  }
  .footer{
    height:100px;
    padding-top:60px;
    color:#999999;
    font-size:16px;
    text-align:center;
    .footer-link{
      a{
        color:#999999;
        display:inline-block;
      }
      span{
        margin:0 10px;
      }
    }
    .copyright{
      margin-top:13px;
    }
  }
}
</style>